package com.zzty.common;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class GunZip {
    public String  uncompress(String gzFileStr,String gunZipPath){
        File file = new File(gzFileStr);
        String filePath1=null;
        try (ZipFile zf = new ZipFile(gzFileStr)){
            Enumeration<? extends ZipEntry> entries = zf.entries();
            while (entries.hasMoreElements()){
                ZipEntry entry = entries.nextElement();
                String zipEntryName = entry.getName();
                File kkFile = new File(gunZipPath);
                if (!kkFile.exists()){
                    kkFile.mkdir();
                }
                String gunUrl=gunZipPath+"//"+zipEntryName;
                FileOutputStream fileOutputStream = new FileOutputStream(gunUrl);
                System.out.println(gunUrl);
                InputStream inputStream = zf.getInputStream(entry);
                byte[] b = new byte[1024*1024*5];
                int length = 0;
                while ((length = inputStream.read(b)) != -1) {
                    fileOutputStream.write(b, 0, length);
                }
                fileOutputStream.close();
                inputStream.close();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return gunZipPath;
    }
}
